package vn.demand.dragon.controller
{
	import com.salesbuilder.control.TabManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import vn.demand.dragon.model.ReferenceProxy;
	import vn.demand.dragon.view.ProjectSearchMediator;
	import vn.demand.dragon.view.ReferenceListMediator;
	import vn.demand.dragon.view.components.ReferenceList;
	
	public class OpenReferenceListCommand extends SimpleCommand
	{
		override public function execute( note:INotification ) :void    
		{
			if (facade.hasMediator(ReferenceListMediator.NAME)) {
				TabManager.openTab(ReferenceList, ReferenceListMediator.NAME);
				return;
			}
			var ui:ReferenceList = TabManager.openTab(ReferenceList, ReferenceListMediator.NAME) as ReferenceList;
            facade.registerProxy(new ReferenceProxy(ReferenceProxy.NAME, null));
            
            facade.registerMediator(new ReferenceListMediator(ui));
            facade.registerMediator(new ProjectSearchMediator(ProjectSearchMediator.NAME, ui.searchForm));
            
            
            var referenceProxy:ReferenceProxy  = facade.retrieveProxy(ReferenceProxy.NAME) as ReferenceProxy;
            referenceProxy.loadReferences();
        }
	}
}